﻿using System;
using DBProvider;
using DBProvider.Providers;

namespace HealthCommunity.Controls
{
	public partial class UCVideoDetail : System.Web.UI.UserControl
	{
		private IVideoProvider _VideoProvider;

		public int VideoID
		{
			get
			{
				return CommonHelper.QueryStringInt("videoid");
			}
		}

		public Video TheVideo
		{
			get;
			set;
		}

		public string VideoAddress
		{
			get;
			set;
		}

		public string ServerURL
		{
			get
			{
				if(Request.Url.Port > 0)
				{
					return string.Format("http://{0}:{1}", Request.Url.Host, Request.Url.Port.ToString());
				}
				else
				{
					return "http://" + Request.Url.Host;
				}
			}
		}

		protected void Page_Load(object sender, EventArgs e)
		{
			if (!IsPostBack)
			{
				hlCancel.NavigateUrl = "~/VideoList.aspx";
				BindVieo();
			}
		}

		private void BindVieo()
		{
			if (VideoID > 0)
			{
				if (_VideoProvider == null)
				{
					_VideoProvider = new VideoProvider();
				}

				TheVideo = _VideoProvider.GetVideo(VideoID);

				this.VideoAddress = TheVideo.VideoAddress;

				//if(VideoAddress.Split('.')[VideoAddress.Split('.').Length - 1].Equals("flv"))
				//{
				//  this.VideoAddress = ServerURL + "/template/FLVPlayer.swf?video=" + VideoAddress;
				//}

				this.Page.Title = TheVideo.VideoTitle;
			}
		}
	}
}